package com.wo56.pushmsgcenter.common.service.impl;

import java.io.Serializable;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.wo56.pushmsgcenter.common.condition.SqlParam;
import com.wo56.pushmsgcenter.common.condition.Wrapper;
import com.wo56.pushmsgcenter.common.dao.interfaces.IDao;
import com.wo56.pushmsgcenter.common.service.interfaces.IService;
import com.wo56.pushmsgcenter.common.utils.ReflectionKitUtil;

public abstract class ServiceImpl<P> implements IService<P> {
	private static final Log logger = LogFactory.getLog(ServiceImpl.class);
    

    public IDao<P> baseDao;
    
	public void setBaseDao(IDao<P> baseDao) {
		this.baseDao = baseDao;
	}
    public IDao<P> getBaseDao(){
    	return this.baseDao;
    }
    public List<P> getValueByWrapper(String column,String type,Object value){
    	SqlParam sqlParam = new SqlParam(column, type, value);
    	Wrapper wrapper = new Wrapper();
    	wrapper.addSqlParam(sqlParam);
    	return this.getValueByWrapper(wrapper);
    }
	@Override
	public List<P> getValueByWrapper(Wrapper wrapper) {
		List<P> pLst = getBaseDao().getValueByWrapper(wrapper);
		return pLst;
	}
	@Override
	public List<P> getAll() {
		List<P> pLst = getBaseDao().getAll();
		return pLst;
	}
	
	@Override
	public P get(Serializable id) {
		return getBaseDao().get(id);
	}

	@Override
	public P save(P p) {
		return getBaseDao().save(p);
	}

	@Override
	public void saveOrUpdate(P p) {
		getBaseDao().saveOrUpdate(p);
	}

	@Override
	public void update(P p) {
		getBaseDao().update(p);
	}

	@Override
	public boolean delete(P p) {
		return getBaseDao().delete(p);
	}

	@Override
	public boolean delete(Serializable id) {
		return getBaseDao().delete(id);
	}

	@Override
	public boolean insertBatch(List<P> list, int size) {
		return getBaseDao().insertBatch(list, size);
	}

	@Override
	public boolean updateBatch(List<P> list, int size) {
		return getBaseDao().updateBatch(list, size);
	}

	@Override
	public boolean saveOrUpdateBatch(List<P> list, int size) {
		return getBaseDao().saveOrUpdateBatch(list, size);
	}


    /**
     * 获取toClass
     *
     * @return
     */
    protected Class<P> poClass() {
        return ReflectionKitUtil.getSuperClassGenricType(getClass(), 0);
    }



}
